<template>
<div>


  <el-select @change="checkUser" v-model="value" placeholder="请选择用户查询待办">
    <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value">
    </el-option>
  </el-select>
  <el-table
      :data="tableData"
      style="width: 100%">
    <el-table-column
        prop="task.id"
        label="任务实例Id">
    </el-table-column>

    <el-table-column
        prop="task.name"
        label="任务名称">
    </el-table-column>

    <el-table-column
        prop="task.assignee"
        label="负责人">
    </el-table-column>
    <el-table-column
        prop="task.cause"
        label="请假原因">
    </el-table-column>
    <el-table-column
        prop="task.holiday"
        label="请假天数">
    </el-table-column>
    <el-table-column
        prop="task.processInstanceId"
        label="历史流程实例id">
    </el-table-column>
    <el-table-column
        prop="task.businessKey"
        label="流程实例绑定的业务key">
    </el-table-column>
    <el-table-column
        prop="task.applyUser"
        label="申请人">
    </el-table-column>

    <el-table-column label="操作" v-if="this.user.rolename=='部门主管' || this.user.rolename=='经理'||this.user.rolename=='人事'">
      <template slot-scope="scope" >

        <el-button
            size="mini"
            type="danger"
            @click="leaderApprove(scope.row)">同意
        </el-button>

        <el-button
            size="mini"
            type="danger"
            @click="leaderReject(scope.row)">驳回
        </el-button>

        <el-button size="mini" type="primary" @click="rwzz(scope.row)">任务追踪</el-button>

      </template>
    </el-table-column>


  </el-table>
</div>
</template>

<script>
export default {
  name: "TaskList",
  data(){
    return{
      tableData:[],
      options: [{
        value: 'zhangsan',
        label: 'zhangsan'
      }, {
        value: 'lisi',
        label: 'lisi'
      }, {
        value: 'xiaomi',
        label: 'xiaomi'
      }],
      value: 'zhangsan',
      user:{
        username:'zhangsan',
        rolename:"经理"
      }
    }
  },
  methods:{
    init(){
      this.axios.post("http://192.168.21.1:8083/taskList",{"username":this.value}).then(res=>{

        this.tableData=res.data
      })
    },
    leaderApprove(row){
      console.log(row)
      this.axios.get("http://192.168.21.1:8083/doTask?taskId="+row.task.id+"&appro=true&taskName="+row.task.name).then(res=>{

        if(res.data=='success'){
          alert("同意申请!!!")
          this.init()
        }
      })
    },
    rwzz(row){
      //新打开一个窗口,让这个窗口显示一张图片,并且这张图片显示当前的进度
      window.open("http://192.168.21.1:8083/viewTask?processInstanceId="+row.task.processInstanceId);
    },
    leaderReject(row){
      this.axios.get("http://192.168.21.1:8083/doTask?taskId="+row.task.id+"&appro=false").then(res=>{

        if(res.data=='success'){
          alert("拒绝申请!!!")
          this.init()
        }
      })
    },
    checkUser(){
      this.init()
    }
  },
  created() {
    this.init();
  }
}
</script>

<style scoped>

</style>